package org.example.controller;

import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import com.wf.captcha.utils.CaptchaUtil;
import org.example.config.CaptureConfig;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@CrossOrigin
@RestController
@RequestMapping
public class CaptureController {
    @RequestMapping("/captcha")
    public void captcha( @RequestParam String key, HttpServletRequest request, HttpServletResponse response)throws Exception{
        //png 类型
        SpecCaptcha captcha=new SpecCaptcha(135,33,4);
        captcha.setCharType(Captcha.TYPE_NUM_AND_UPPER);
        CaptureConfig.CAPTURE_MAP.put(key,captcha.text().toLowerCase());
        CaptchaUtil.out(captcha,request,response);

        /*//算术类型
        ArithmeticCaptcha captcha1=new ArithmeticCaptcha(135,33);
        captcha1.setLen(2);
        captcha1.getArithmeticString();
        captcha1.text();
        CaptureConfig.CAPTURE_MAP.put(key,captcha1.text().toLowerCase());
        CaptchaUtil.out(captcha1,request,response);*/
    }
}
